const express = require("express")
const router = express.Router()
const {addRecomment,delRecomment,searchRecomment,updateRecomment} = require("../control/recomment")
const {SuccessModel,ErrorModel} = require("../model/resModel")
const passport = require("passport")

router.post("/add",passport.authenticate("jwt",{session:false}),async (req,res)=>{  
  console.log(req.body);
  
  let data =await addRecomment(req,res)
  if(data.affectedRows>0){
    res.json(new SuccessModel("添加成功"))
  }else{
    res.json(new ErrorModel("添加失败"))
  }
})

router.post("/update",async (req,res)=>{    
  let data =await updateRecomment(req,res)
  
  if(data.affectedRows>0){
    res.json(new SuccessModel("更新成功"))
  }else{
    res.json(new ErrorModel("更新失败"))
  }
})
  router.post("/del",passport.authenticate("jwt",{session:false}),async (req,res)=>{
    let data =await delRecomment(req,res)
    if(data.affectedRows>0){
      res.json(new SuccessModel("删除成功"))
    }else{
      res.json(new ErrorModel("删除失败"))
    }
  })
  router.get("/search",async (req,res)=>{
    let data =await searchRecomment(req,res)
    if(data.length>0){
      res.json(new SuccessModel(data,"查找成功"))
    }else{
      res.json(new ErrorModel("查找失败"))
    }
  })


module.exports=router
